﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02ConverterBinToDec
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a bianry number(no spaces, just zeros and ones):");
            string nBin = Console.ReadLine();
            List<int> binList = new List<int>();
            int charToInt;
            int value;
            int sum = 0;
            foreach (var item in nBin)
            {
                charToInt = (int)(item - '0');
                binList.Add(charToInt);
            }
            for (int i = 0, k = binList.Count - 1; i < binList.Count && k >= 0 ; i++, k--)
            {
                value = binList[i] * (int)Math.Pow(2,k);
                sum = sum + value;
            }
            Console.Write("The number in decimal is:" + sum);
            Console.WriteLine();
        }
    }
}
